﻿@using PagedList.Mvc;
@using System.Globalization;
@using LKVMLMLib;
@{
    Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
}

@using (Html.BeginForm("ListGH", "GetHelp", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-inline" }))
{
    <div id="wrapper">
        <div class="clear-fix"></div>
        <div class="row">
            <div style=" min-height: 110px; padding-left: 30px; ">
                <h3 class="page-header">Danh sách GH</h3>
                <span style="color:orangered;">@ViewBag.Msg</span><br />
                <input type="text" name="Username" class="form-control">
                @Html.DropDownList("status", new SelectList(
                       new List<Object>{
                       new { value =0 , text = "New Active"},
                       new { value =1 , text = "Proccesing"},
                         new { value =3 , text = "Confirm"}
                    },
                  "value",
                  "text",
                 null), new { @class = "combobox" })
                @{ DateTime a = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
                    DateTime b = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddMonths(1).AddDays(-1);
                }

                <input type="text" name="Fromdate" class="form-control inputBox" value="@a">
                <input type="text" name="Todate" class="form-control inputBox" value="@b">
                <button type="submit" class="btn_submit btn btn-default">Tìm kiếm</button>
            </div>
        </div>
        <!-- /.row -->
        <div class="row">
            <div class="col-lg-12">
                <div class="panel-body">
                    <div class="dataTable_wrapper">
                        <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                            <thead>
                                <tr style="font-family:'Times New Roman'">
                                    <th>STT</th>
                                    <th>Created</th>
                                    <th>GH User</th>
                                    <th>Status</th>
                                    <th>Value</th>
                                    <th>PH User</th>
                                    <th>PH Mobile</th>
                                    <th>Remaining</th>
                                    <th>Type</th>
                                    <th>Option</th>
                                </tr>
                            </thead>
                            <tbody style="font-family:'Times New Roman'">
                                @{int j = 0;}
                                @foreach (var item in ViewBag.GHs)
                                {

                                    j++;
                                    <tr>
                                        <td>@j</td>
                                        <td>@item.CreateDate</td>
                                        <td>@item.UserName</td>
                                        <td>@item.StatusName</td>
                                        <td>@item.Amount</td>
                                        <td></td>
                                        <td></td>
                                        <td>@item.Remaining</td>
                                        <td>@item.TypeName</td>
                                        <td>
                                            <a href="javascript:void(0);" class="anchorDetail" data-id="@item.UserId">View</a> 
                                            @if (item.Status == 0)
                                            {
                                                <b>|</b>
                                                <a href='@Url.Action("CreateTransferOrder", "GetHelp", new { userGH = item.UserId, ghId = item.Id })'>Create PH</a><b> |</b>
                                                <a href='@Url.Action("DeleteGH", "GetHelp", new { ghId = item.Id })' class="doactive">Delete</a>
                                            }
                                        </td>
                                    </tr>
                                    if (item.TransferOrder.Count > 0)
                                    {
                                        foreach (var ts in item.TransferOrder)
                                        {
                                            <tr>
                                                <td></td>
                                                <td>@ts.CreateDate.ToString("dd/MM/yyyy hh:mm:ss")</td>
                                                <td></td>
                                                @if (ts.Status == 0)
                                                {
                                                    <td>Proccesing</td>
                                                }
                                                else if (ts.Status == 1)
                                                {
                                                    <td>Bad</td>
                                                }
                                                else
                                                {
                                                    <td>Confirm</td>
                                                }
                                                <td>@ts.Amount</td>
                                                <td>@ts.PH_Name</td>
                                                <td>@ts.PH_Mobile</td>
                                                <td></td>
                                                <td></td>
                                                <td>
                                                    Option
                                                </td>
                                            </tr>
                                        }
                                    }
                                }

                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            <!-- /.panel -->
        </div>
    </div>
    <div class="dataTables_paginate paging_full_numbers pull-right" id="dyntable_paginate">
        @Html.PagedListPager((PagedList.IPagedList)Model, page => Url.Action("ListGH", new { page, status = ViewBag.status, Fromdate = ViewBag.DateFrom, Todate = ViewBag.Todate }))
    </div>
    <script src="~/Scripts/fm.datetator-fo.jquery.js"></script>
    <link href="~/Scripts/fm.datetator.jquery.css" rel="stylesheet" />
    <script src="~/Scripts/fm.datetator.jquery.js"></script>
        <script type="text/javascript">
            $('.inputBox').datetator();
            $('.doactive').on('click', function () {
                return confirm('bạn có chắc chắn không ?');
            });
            $('.confirmation').on('click', function () {
                return confirm('bạn có chắc chắn muốn xóa?');
            });
        </script>
        <div id='myPhModal' class='modal fade' role="dialog">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">PH Information</h4>
                    </div>
                    <div class="modal-body">
                        <div id='gHContent'></div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    </div>
                </div>
            </div>

        </div>
        <!-- Scrip modal-->
 <script>
     var TeamDetailPostBackURL = '/GetHelp/showModalGhInfo';
    $(function () {
        $(".anchorDetail").click(function () {
            //debugger;
            var $buttonClicked = $(this);
            var id = $buttonClicked.attr('data-id');
            var options = { "backdrop": "static", keyboard: true };
            $.ajax({
                type: "GET",
                url: TeamDetailPostBackURL,
                contentType: "application/json; charset=utf-8",
                data: { "UserId": id },
                datatype: "json",
                success: function (data) {
                    debugger;
                    $('#gHContent').html(data);
                    $('#myPhModal').modal(options);
                    $('#myPhModal').modal('show');

                },
                error: function () {
                    alert("Dynamic content load failed.");
                }
            });
        });
        $("#closbtn").click(function () {
            $('#myPhModal').modal('hide');
        });
    });

</script>
}
